<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  medias
 */

class m_medias_services_ParameterService extends f_core_Service
{
	/**
	 * @var m_medias_services_ParameterService
	 */
	private static $instance;
	
	/**
	 * Constructor
	 */
	private function __construct()
	{
		// Code if needed...
	}
	
	/**
	 * @return m_medias_services_ParameterService
	 */
	public static function getInstance()
	{
		if (self::$instance === null)
		{
			self::$instance = new self();
		}
		return self::$instance;
	}
	
	public function getParametersByFolderId($folderId, $lang)
	{
		$relManager = f_relation_Manager::getInstance();
		$docProvider = $this->getDocumentProvider();
		
		$dbParentIds = $relManager->getParentsIdsByDocType($folderId, array("modules_backoffice/folder", "modules_backoffice/rootNode"), $lang);
		
        if(count($dbParentIds) > 0)
        {
            foreach($dbParentIds as $parentId)
            {
               $parentIds[] = intval($parentId['parent_id']);
            }            
        }

		$parentIds[] = intval($folderId);		

		return $docProvider->loadDocuments("modules_medias/parameter")->whereIsEqual("folderId", $parentIds)->retrieveDocuments($lang);
	}

    public function getResizeModeLabel()
    {
        $values = array();
        $locale = f_locale_Manager::getInstance();
        for($i=1; $i <= 4; $i++)
        {
            $values[$i] = $locale->getLocale("medias.forms.crop".$i);
        }

        return $values;
    }
}